# encoding: utf-8
# 解决thread,multiprocess,logging混用时死锁的问题，使用第三方类库pythonb-atfork,
# python-atfork安装
# 进入ucloud-agent下的patched/python-atfork目录，执行python setup.py install
import atfork.stdlib_fixer

atfork.monkeypatch_os_fork_functions()
atfork.stdlib_fixer.fix_logging_module()

# import logging
import sys

from app import create_app

application = create_app(flask_config='development')

# 重定向日志到/usr/local/logs/ucloud-agent.log
# logging.basicConfig(filename='/usr/local/logs/ucloud-agent.log', filemode='w',
#                     level=logging.DEBUG,
#                     format="%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s"
#                     )
reload(sys)
sys.setdefaultencoding('utf8')

if application.config['socketio_app']:
    socketio_app = application.config['socketio_app']
    socketio_app.run(app=application, host='0.0.0.0', port=5000, debug=False)
else:
    application.run(host='0.0.0.0', port=5000, debug=False)
